package thinkingJava.chapter10;

interface Counter {
	int next();
}

public class LocalInnerClass {
	private int count = 0;
	Counter getCount(final String name) {
		class LocalCounter implements Counter {
			LocalCounter() {
				System.out.println("LocalCount");
			}
			public int next() {
				System.out.println(name);
				return count++;
			}
		}
		return new LocalCounter();
	}
	Counter getCount2(final String name) {
		return new Counter() {
			public int next() {
				System.out.println(name);
				return count++;
			}
		};
	}
	public static void main(String[] args) {
		LocalInnerClass lic = new LocalInnerClass();
		Counter c1 = lic.getCount("local class"),
			c2 = lic.getCount2("innner anonymouse class");
		for (int i = 0; i < 5; i++) {
			System.out.print(c1.next());
		}
		for (int i = 0; i < 5 ; i++) {
			System.out.print(c2.next());
		}
	}
}
